cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

# set the project name
project(MyProject)
set(APP_NAME mainexe)
set(CMAKE_CXX_STANDARD 11)

set(GNUC 0)
set(MSVC 0)
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
    set(GNUC 1)
endif()
if("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
    set(MSVC 1)
endif()

message(STATUS "CMAKE_C_COMPILER:         ${CMAKE_C_COMPILER} (id ${CMAKE_C_COMPILER_ID}, MSVC:${MSVC}, GNUC:${GNUC})")

if(${MSVC})
	message(STATUS "Set boost")
	set(Boost_DEBUG ON)
    set(BOOST_ROOT "E:/boost/boost_1_80_0") #Set Boost root dir
	set(BOOST_INCLUDEDIR "E:/boost/boost_1_80_0/boost")
	set(BOOST_LIBRARYDIR "E:/boost/boost_1_80_0/stage/lib")
	set(Boost_LIB_PREFIX "lib")
    set(Boost_USE_STAIIC_LIBS ON)
    set(Boost_USE_MULITHREADED ON)
    set(Boost_ARCHITECTURE "-x64")
endif()

message(STATUS "")
find_package(Boost COMPONENTS regex filesystem coroutine context REQUIRED)

if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
message( STATUS "Boost_ROOT = ${BOOST_ROOT}")
message( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}")
message( STATUS "Boost_LIBRARY_DIRS = ${Boost_LIBRARY_DIRS}")
message( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
message( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}")
endif()
message(STATUS "")

# HttpServer
set(HTTPSERVER
HttpServer/BeastHttpServerRequestHandler.h
HttpServer/BeastHttpServerRequestHandler.cpp
HttpServer/BeastHttpServer.h
HttpServer/BeastHttpServer.cpp
HttpServer/HttpServerModule.h
HttpServer/HttpServerModule.cpp
)
source_group(HttpServer FILES ${HTTPSERVER})
#Utility
##Json
set(UTILITY_JSON
Utility/CJson/cJSON.h
Utility/CJson/cJSON.cpp
Utility/CJson/json_reflection_arg_macros.h
Utility/CJson/json_reflection_utility.h
Utility/CJson/JsonHandler.h
Utility/CJson/JsonHandler.cpp
Utility/CJson/WebCommonOutputTemplate.h
)
source_group(Utility FILES ${UTILITY_JSON})
#WebModule
set(WEBMODULE
WebModule/CommonEnum.h
WebModule/CommonStruct.h
WebModule/WebModule.h
WebModule/WebModule.cpp
)
source_group(WebModule FILES ${WEBMODULE})

list(APPEND SRC_FILES
    main.cpp
    ModuleBase.cpp
	ModuleBase.h
)

if(${MSVC})
add_definitions(-D_WIN32_WINNT=0x0601)
endif()

# add the executable
add_executable(${APP_NAME} ${UTILITY_JSON} ${HTTPSERVER} ${WEBMODULE} ${SRC_FILES})
if(${GNUC})
target_link_libraries(${APP_NAME} libpthread.so pthread ${Boost_LIBRARIES})
endif()
if(${MSVC})
target_link_libraries(${APP_NAME} ${Boost_LIBRARIES})
endif()


message(STATUS "")
message(STATUS "CMAKE_BINARY_DIR:         ${CMAKE_BINARY_DIR}")
message(STATUS "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "CMAKE_SOURCE_DIR:         ${CMAKE_SOURCE_DIR}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "PROJECT_BINARY_DIR:       ${PROJECT_BINARY_DIR}")
message(STATUS "PROJECT_SOURCE_DIR:       ${PROJECT_SOURCE_DIR}")
message(STATUS "CMAKE_MODULE_PATH:        ${CMAKE_MODULE_PATH}")
message(STATUS "CMAKE_COMMAND:            ${CMAKE_COMMAND}")
message(STATUS "CMAKE_ROOT:               ${CMAKE_ROOT}")
message(STATUS "CMAKE_SYSTEM:             ${CMAKE_SYSTEM}")
message(STATUS "CMAKE_SYSTEM_NAME:        ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_SYSTEM_VERSION:     ${CMAKE_SYSTEM_VERSION}")
message(STATUS "CMAKE_SYSTEM_PROCESSOR:   ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "CMAKE_SKIP_RPATH:         ${CMAKE_SKIP_RPATH}")
message(STATUS "CMAKE_VERBOSE_MAKEFILE:   ${CMAKE_VERBOSE_MAKEFILE}")
message(STATUS "CMAKE_C_FLAGS:            ${CMAKE_C_FLAGS}")
message(STATUS "CMAKE_BUILD_TYPE:         ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_C_COMPILER:         ${CMAKE_C_COMPILER} (id ${CMAKE_C_COMPILER_ID}, MSVC:${MSVC}, GNUC:${GNUC})")
message(STATUS "CMAKE_CXX_STANDARD:       ${CMAKE_CXX_STANDARD}")
message(STATUS "CMAKE_AR:                 ${CMAKE_AR}")
message(STATUS "CMAKE_RANLIB:             ${CMAKE_RANLIB}")
message(STATUS "CMAKE_INSTALL_PREFIX:     ${CMAKE_INSTALL_PREFIX}")
message(STATUS "CMAKE_THREAD_LIBS_INIT:   ${CMAKE_THREAD_LIBS_INIT}")
message(STATUS "CMAKE_INSTALL_PREFIX:     ${CMAKE_INSTALL_PREFIX}")
message(STATUS "")

